<template>
	<view class="main_invitationCode">
		<view class="main_invitationCode_top">
			<view style="color: #F33340; font-size: 36rpx; font-weight: bold;margin-top: 40rpx;">
				分享好友享好礼
			</view>
			<view class="mt10" style="color: #F33340; font-size: 28rpx;">
				快来保存二维码分享给你的好友吧
			</view>
		</view>
		<view class="main_invitationCode_content">
			<view class="main_invitationCode_content_image">
				<view class="main_invitationCode_content_image_ewm">
					<image 
					style="width: 100%;height: 100%;"
					:src="ewm ? uploadImgUrl + ewm : computendMorentu"></image>
				</view>
				<view class="main_invitationCode_content_text">
					<text>1.打开微信</text>
					<text>2.用微信扫二维码</text>
				</view>
			</view>
			
			<view class="main_invitationCode_content_btn">
				<newBtn name="长按图片分享给好友" bgColor="#F33340" color="#FFF" :share="true"></newBtn>
				<view style="height: 20rpx;"></view>
				<newBtn class="mt10 btnow" name="长按图片保存到相册" bgColor="#FFE3E3" color="#F33340" @longpress="press"></newBtn>
			</view>
			
		</view>
		
	</view>
</template>

<script>
	import {getWxQRCode} from '@/api/global.js'
	import newBtn from "@/components/newBtn/newBtn.vue"
	import {uploadImgUrl} from "@/utils/request.js"
	export default {
		options:{styleIsolation:'shared'},
		components:{
			newBtn
		},
		computed:{
			computendMorentu(){
				return this.$store.state.morentu
			}
		},
		name:"invitationCode",
		data() {
			return {
				uploadImgUrl,
				ewm:'',//二维码路径
			};
		},
		created() {
			this.getCodeUrl()
		},
		onShareAppMessage(){
			
		},
		methods:{
			press(){
				console.log(99)
				let _this = this;
				uni.downloadFile({
					url:this.uploadImgUrl + this.ewm,
					success: (r) => {
						console.log(r)
						uni.saveImageToPhotosAlbum({
							filePath:r.tempFilePath,
							success() {
								_this.Utils.toast(`保存成功`);
							},
							fail() {
								_this.Utils.toast(`保存失败`);
							}
						})
					}
				})
				
			},
			//获取二维码链接展示
			async getCodeUrl(){
				let userId = uni.getStorageSync('visitorLoginInfo') ? JSON.parse(uni.getStorageSync('visitorLoginInfo')).MallMember.memberId : ''
				let res = await getWxQRCode({
					scene:`${userId}_2`
				})
				if(res.code == 2000){
					this.ewm = res?.data?.info
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
.main_invitationCode{
	width: 100%;
	height: 100%;
	box-sizing: border-box;
	position: relative;
	overflow-y: scroll;
	.main_invitationCode_top{
		width: 100%;
		height: 280rpx;
		background: linear-gradient(165.897365160267deg, rgba(255, 227, 227, 1) 0%, rgba(255, 255, 255, 1) 69%);
		border-radius: 20rpx 20rpx 0 0;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.main_invitationCode_content{
		width: 100%;
		z-index: 99999;
		padding: 0 40rpx;
		box-sizing: border-box;
		.main_invitationCode_content_image{
			position: absolute;
			top: 200rpx;
			left: 50%;
			transform: translateX(-50%);
			width: 85%;
			height: 420rpx;
			border: 1px solid pink;
			background: linear-gradient(177.875379078024deg, rgba(255, 227, 227, 1) 1%, rgba(255, 255, 255, 1) 127%);
			border-radius: 20rpx;
			
			.main_invitationCode_content_image_ewm{
				width: 260rpx;
				height: 260rpx;
				background-color: #FFF;
				border-radius: $border_radius_10;
				margin: 50rpx auto;
				
			}
		}
		.main_invitationCode_content_text{
			width: 100%;
			text-align: center;
			color: #F33340;
			font-size: $font_size_12;
			margin-top: 50rpx;
			text{
				margin-left: 20rpx;
			}
		}
	}
	.main_invitationCode_content_btn{
		margin-top: 360rpx;
	}
}


</style>